package com.labofjet.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;

import com.labofjet.aspect.ShadowAspect;

@Entity
@EntityListeners(ShadowAspect.class)
public class Student implements Shadowable{
	@Id
	@GeneratedValue
	private long id;
	
	private String name;
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy="student", orphanRemoval=true)
	List<Phone> phones;
	
	public List<Phone> getPhones() {
		return phones;
	}

	public void setPhones(List<Phone> phones) {
		this.phones = phones;
	}

	public void setId(long id) {
		this.id = id;
	}

	public long getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Override
	public String toString(){
		return id + "_" + name + "_" + phones;
	}

	@Override
	public Object getShadowObject() {
		StudentShadow ss = new StudentShadow();
		ss.setName(name);
		List<PhoneShadow> list = new ArrayList<PhoneShadow>();
		for(Phone p : phones){
			PhoneShadow ps = (PhoneShadow)p.getShadowObject();
			list.add(ps);
		}
		ss.setPhones(list);
		return ss;
	}
	
	@Override
	public boolean equals(Object obj) {
		// TODO Auto-generated method stub
		return super.equals(obj);
	}
}
